<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GonzalesToolsEntertainment.aspx.cs" Inherits="GonzalesToolsEntertainment" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <link href="WebStyle.css" rel="stylesheet" type="text/css" />
</head>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript">

    function ReCalCostPerHead () {
        
        var TotalCost = parseFloat(document.getElementById("TextBox_TotalCost").value.replace(/,/g,''));
        var TotalAttendees = 0;
        
        for (var x = 0; x < document.forms[0].elements.length; x++) {
            
            if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                
                var RowID = document.forms[0].elements[x].name.substring (0, 36);
                
                if (document.getElementById(RowID + "TextBox_Attendees").value.length > 0 || 
                    document.getElementById(RowID + "TextBox_Title").value.length > 0 ||
                    document.getElementById(RowID + "TextBox_Company").value.length > 0) {
                        
                    document.getElementById(RowID + "_IsEmpty").value = 0;  // not empty
                    TotalAttendees++;                    
                } else {
                    document.getElementById(RowID + "_IsEmpty").value = 1;  // is empty                
                }
            }               
        }   // for
        
        document.forms[0].HiddenField_TotalParticipants.value = TotalAttendees;
        
        if (TotalAttendees > 0) {
            
            var TotalCostPerHead = Round((TotalCost/TotalAttendees), 2);
        
            for (var x = 0; x < document.forms[0].elements.length; x++) {
                
                if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                    
                    var RowID = document.forms[0].elements[x].name.substring (0, 36);
                    
                    if (document.getElementById(RowID + "_IsEmpty").value == 0) {
                            
                        document.getElementById(RowID + "TextBox_CostPerHead").value = TotalCostPerHead;                           
                    }                                               
                }               
            }   // for        
        }                   
    }
    
    function Validate() {
    
        var valid = true;
        
        if (document.forms[0].TextBox_Purpose.value.length == 0) {
            document.forms[0].TextBox_Purpose.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_Purpose.className = "FormTextBox";
        }
        
        if (document.forms[0].TextBox_TotalCost.value.length == 0) {
            document.forms[0].TextBox_TotalCost.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_TotalCost.className = "FormTextBox";
        }        
        
        
        for (var x = 0; x < document.forms[0].elements.length; x++) {
            
            if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                
                var RowID = document.forms[0].elements[x].name.substring (0, 36);
                
                if (document.getElementById(RowID + "TextBox_Attendees").value.length > 0 || 
                    document.getElementById(RowID + "TextBox_Title").value.length > 0 ||
                    document.getElementById(RowID + "TextBox_Company").value.length > 0) {
                    
                    // this row not empty
                    // now check if all fill in
                    if (document.getElementById(RowID + "TextBox_Attendees").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Attendees").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Attendees").className = "DetailGridTextBox";
                    }                                                                                                      
                    
                    if (document.getElementById(RowID + "TextBox_Title").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Title").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Title").className = "DetailGridTextBox";
                    }
                    
                    if (document.getElementById(RowID + "TextBox_Company").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Company").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Company").className = "DetailGridTextBox";
                    }                                        
                } 
            }               
        }   // for    
        
        if (!valid) {
            alert("Highlighted fields are mandatory");
        }    
        
        return valid;
    
    }  
    
    function PassParameter()
	{
	    document.getElementById("hiddenClose").value = "true";
	    return true;
	}
	  
</script>
<body>
<form id="Form1" method="post" runat="server">
  <table width="100%" border="0" cellpadding="2" cellspacing="1">
    <tr>
      <td height="40" class="PageTitle"><asp:Label ID="Label_Title" runat="server" Text='Entertainment'></asp:Label></td>
    </tr>
    <tr>
      <td><asp:Table CellPadding="5" CellSpacing="0" ID="Table_MessageBox" Width="100%" runat="server" Visible="false">
        <asp:TableRow>
          <asp:TableCell CssClass="ErrorBox" ></asp:TableCell>
        </asp:TableRow>
      </asp:Table></td>
    </tr>
    <tr>
      <td><table width="100%" border="0" cellpadding="5" cellspacing="0" class="FormBorder">
        <tr>
          <td width="130" class="FormLineItemAlt"><asp:Label CssClass="FormField" ID="Label2" runat="server" Text='Purpose:' /></td>
          <td width="88%" class="FormLineItemAlt"><asp:TextBox ID="TextBox_Purpose" runat="server"
                  CssClass="FormTextBox" MaxLength="50" Rows="50" Width="200px"></asp:TextBox></td>
        </tr>
        <tr>
          <td class="FormLineItem"><asp:Label CssClass="FormField" ID="Label_GovOfficial" runat="server" Text='Gov. Official:' /></td>
          <td class="FormLineItem"><asp:CheckBox ID="CheckBox_IsGovOfficial" runat="server" /></td>
        </tr>
        <tr>
          <td class="FormLineItemAlt"><asp:Label CssClass="FormField" ID="Label_TotalCost" runat="server" Text='Total Cost:' /></td>
          <td class="FormLineItemAlt"><asp:TextBox CssClass="FormTextBox" ID="TextBox_TotalCost" runat="server" TextMode="SingleLine" /></td>
        </tr>
        <tr>
          <td colspan="2" class="FormLineItem"><asp:Table ID="Table_ClaimDetailGrid" runat="server" Width="100%" CellPadding="0" CellSpacing="1" CssClass="FormBorder"> </asp:Table></td>
          </tr>
        <tr>
          <td colspan="2" align="right" class="FormLineItem"><span class="FormLineItemAlt">
            <asp:Button ID="Button_PasteNameList" runat="server" CssClass="FormButton" OnClick="Button_PasteNameList_Click"
                  Text="Paste from Clipboard" />            
            <asp:Button ID="Button_Copy" runat="server" OnClick="Button_Copy_Click" Text="Copy to Clipboard" CssClass="FormButton" />            
          </span></td>
        </tr>
        <tr>
          <td colspan="2" class="FormLineItemAlt"><asp:Button CssClass="FormButton" ID="Button_AddMoreRow" runat="server" Text="Add More Items" OnClick="Button_AddMoreRow_Click" />          
              <asp:Button ID="Button_Remove" runat="server" CssClass="FormButton" OnClick="Button_Remove_Click"
                  Text="Remove Selected Items" />
              <asp:Button ID="Button_ClearAll" runat="server" OnClick="Button_ClearAll_Click" Text="Clear All Items" CssClass="FormButton" />
              <asp:HiddenField ID="HiddenField_TotalParticipants" runat="server" />
          </td>
        </tr>
        <tr>
            <td class="FormLineItem"><asp:Button ID="Button_Calculate" runat="server" CssClass="FormButton" Text="Calculate Cost per head" />
            <asp:Button ID="Button_Submit" Text="Save" runat="server" CssClass="FormButton" OnClick="Button_Submit_Click" />
              <asp:Button ID="Button_Done" runat="server" CssClass="FormButton" Text="Save & Exit" OnClick="Button_Done_Click" />
              <asp:Button ID="Button_Cancel" runat="server" CssClass="FormButton" Text="Cancel" /></td>
        </tr>
      </table></td>
    </tr>
    <input name="hiddenClose" type="hidden" class="FormTextBox" id="hiddenClose" />  
  </table>
</form>
</body>
<script language="javascript" type="text/javascript">

    ReCalCostPerHead();
</script>
</html>
